// Figure 1: Support for War with China
// Andrew Gooch
// Yale University
// July 2018

// CREATE OVERALL TREATMENT EFFECT PLOT
// TOP PANEL OF FIGURE 1
// This do file creates the plot from the regression model and the correspondning table for the appendix

// location of data -> be sure to replace directory location with your own directory before running!
cd "C:\Users\agooch\Dropbox\Working papers\War with China\data"
use War_with_China_Experiment_Gooch_cleaned
cd "C:\Users\agooch\Dropbox\Working papers\War with China\code"
//////////////////////////////////////////// 
// OUTREG TABLES FOR EACH OUTCOME MEASURE //
////////////////////////////////////////////


* Sample lincom two variables code
* local t1 : variable label `var1'
* local t2 : variable label `var2'
* qui lincom  `var1' -`var2'
* local fx = `r(estimate)'
* local tstat = abs(`r(estimate)'/`r(se)')
* local pvalue=ttail(`r(df)',`tstat')*2
* and 95% cI of lincom
* local  upperci= r(estimate) + invttail(r(df),0.025)*r(se)
* local lowerci = r(estimate) + invttail(r(df),0.975)*r(se)

////////////////////////////////////////////////////
// feeling thermometer with partisans broken out //
////////////////////////////////////////////////////

label var war_exp "Support for War with China (0-1)"

// the regression
reg war_exp cue_t1 Inevitable_t2 HumanRights_t3 Democrats Independents Dem_cue_1 Dem_Inevt_2 Dem_HR_3 Ind_cue_1 Ind_Inevt_2 Ind_HR_3 ///
Turnout_VLikely Turnout_SLikely Northeast Midwest West Female Education Age AA Hispanic 

// dems
lincom Inevitable_t2 + Dem_Inevt_2
lincom HumanRights_t3 + Dem_HR_3



/* The following block of code makes the MFX plot */

/* Make all changes here: */

/* Graph Name for Export */
local graphfilename = "Dem_war_support"

/* Define Table Title Here */
local titletext = " "

/* Define note and caption text here. Note comes first. */
local notetext = "Non-response excluded, n=719. Plotted quantities are change in outcome relative to Control with 95% CI."


/* STARTING HERE, THIS BLOCK SHOULD REMAIN FIXED */

local outcomelab : variable label `e(depvar)'

gen _linctr=.
gen _lincomest=. 
gen _lincomtext=""
gen _lowerci=. 
gen _upperci=. 

local ctr=0
local tvar="cue_t1"
local tvar2="Dem_cue_1"
include 00_sub_doonevarlincomforgraph.do
local tvar="Inevitable_t2"
local tvar2="Dem_Inevt_2"
include 00_sub_doonevarlincomforgraph.do 
local tvar="HumanRights_t3"
local tvar2="Dem_HR_3"
include 00_sub_doonevarlincomforgraph.do 

labmask _linctr, values(_lincomtext)

qui summ _linctr
local ctrmin=r(min)
local ctrmax=r(max)
local rangemin=r(min)-.50
local rangemax=r(max)+.50

twoway (scatter _lincomest _linctr, mcolor(black) msymbol(circle) yscale(r(-0.2 0.2)) ylabel(#5) ) (rcap _lowerci _upperci _linctr, lcolor(black)), ytitle("Change in Support for War Relative to Control", size(small) margin(right)) yline(0, lpattern(dash) lcolor(black)) xscale(range(`rangemin' `rangemax')) xtitle("") xlabel(`ctrmin'(1)`ctrmax', labels labsize(small) valuelabel) xmtick(none) title("Democrats", size(small)) caption("`captiontext'", size(small) color(black) span) legend(off) scheme(s1mono) name("`graphfilename'", replace)
graph export "`graphfilename'.pdf", as(pdf) replace

capture drop _linctr _lincomest _lincomtext _lowerci _upperci
capture label drop _linctr

/* END FIXED BLOCK */
/* End MFX plot block */

lincom cue_t1 - Inevitable_t2
local lincom1=r(estimate)
local tstat1= abs(`r(estimate)'/`r(se)')
local pvalue1=ttail(`r(df)',`tstat1')*2
lincom cue_t1 - HumanRights_t3
local lincom2=r(estimate)
local tstat2= abs(`r(estimate)'/`r(se)')
local pvalue2=ttail(`r(df)',`tstat2')*2
lincom HumanRights_t3 - Inevitable_t2
local lincom3=r(estimate)
local tstat3= abs(`r(estimate)'/`r(se)')
local pvalue3=ttail(`r(df)',`tstat3')*2
summ war_exp if e(sample) & treatment == 1
local control=r(mean)
outreg2 using warsupport.doc, replace ctitle(War Support) bracket ///
addstat("Control Group Mean (0-1)", `control') label ///
addnote("All independent variables are dummy such that 1=yes and 0=no, except age and education. Excluded categories are: Control group, Republicans, might or might not turnout, Resides in the South, and Male. Because of the interactions by party, main treatment effects represent Republicans only.")





























